//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    imgUrls: [
      '/imgs/goods/100nrf2.jpg',
      '/imgs/goods/chaoneng2.jpg',
      '/imgs/goods/diao2.jpg',
      '/imgs/goods/jsb2.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 2000,
    goodList:[
      { 
        good_id: 120,
        good_url:'pages/json/index/index',
        good_image_url: '/imgs/goods/mgj2.jpg',
        good_name: '张麻子剪刀,日出东方,孤独求败',
        good_promotion_price: 1.89,
        good_sale_price: 18.9
      },
      {
        good_id: 121,
        good_url: 'pages/json/index/index',
        good_image_url: '/imgs/goods/nice2.jpg',
        good_name: '张麻子剪刀,日出东方,孤独求败',
        good_promotion_price: 1.89,
        good_sale_price: 28.9
      },
      {
        good_id: 122,
        good_url: 'pages/json/index/index',
        good_image_url: '/imgs/goods/100nrf2.jpg',
        good_name: '张麻子剪刀,日出东方,孤独求败',
        good_promotion_price: 1.89,
        good_sale_price: 18.9
      },
      {
        good_id: 123,
        good_url: 'pages/json/index/index',
        good_image_url: '/imgs/goods/yyl2.jpg',
        good_name: '张麻子剪刀,日出东方,孤独求败',
        good_promotion_price: 1.89,
        good_sale_price: 18.9
      },
      {
        good_id: 124,
        good_image_url: '/imgs/goods/diao2.jpg',
        good_name: '张麻子剪刀,日出东方,孤独求败',
        good_promotion_price: 1.89,
        good_sale_price: 18.9
      },
      {
        good_id: 125,
        good_url: 'pages/json/index/index',
        good_image_url: '/imgs/goods/chaoneng2.jpg',
        good_name: '张麻子剪刀,日出东方,孤独求败',
        good_promotion_price: 1.89,
        good_sale_price: 18.9
      }
    ]
  },

  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  toDetail: function(e){
    var good_id = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/detail/index'
    })
  }
})
